<?php
namespace Unicom\Controller;
use Think\Controller;



abstract class DomainObject {
	private $group;
	public static function create() {
		return new static();
	}

	public function __construct() {
		$this->group = static::getGroup();
	}

	static function getGroup() {
		return "default";
	}

}

class Person {

}

class User extends DomainObject {
	private $name;
	public function __construct() {
		parent::__construct();
		throw new \Exception("error.....");
	}
	static function getGroup() {
		return "User";
	}

}

class Document extends DomainObject {
	public $age;
	static function getGroup() {
		return "Document";
	}

	public function __set($propery, $value) {
		var_dump("__set", $propery, " v:" . $value);
		$method = "set{$propery}";
		if (method_exists($this, $method)) {
			$this->$method($value);
		}
	}

	public function setName($name) {
		$this->name = $name;
	}

	public function __call($methedname, $args) {
		if (method_exists($this, $methedname)) {
			$this->methedname($args);
		}

	}

}

class TestController extends Controller {
	public function test() {
		$file = "/Volumes/data/php_workspace/cp/16_06_03.log";
		$handle = fopen($file, "r"); //读取二进制文件时，需要将第二个参数设置成'rb'

		//通过filesize获得文件大小，将整个文件一下子读到一个字符串中
		$contents = fread($handle, filesize($file));
		fclose($handle);
		$rule = 'INFO';
		preg_match($rule, $contents, $result);
		var_dump($result);
	}

	public function test1() {
		$sql = "select * from (select * from cp.cp_verify_phone where DATE_FORMAT(create_time,'%Y-%m-%d')='2016-06-13' and mocontent='WS') as v left join cp.cp_privence as p on left (v.mophone,7)=p.dcmobile";
		$model = M('cp.verify_phone', 'cp_');
		$data = $model->query($sql);
		var_dump($data);
	}

	public function test3() {
		$sql = "select * from cp.cp_blacklist where phone='13236939891'";
		$model = M('cp.blacklist', 'cp_');
		$data = $model->query($sql);
		var_dump($data);
	}

	public function testPerson() {

		// $p = new \Person("fighting",33);
		var_dump($p);
		$arr = array();
		var_dump(is_array($arr), is_object($arr), is_null($a));
		var_dump(APP_PATH . MODULE_NAME . "Common/person.php");
		$xml = "<xml><name>fighting</name></xml>";
		$setting = simplexml_load_string($xml);
		var_dump((string) $setting->name);

		$d = Document::create();
		$d->name = "xml";
		var_dump($u, $d);

		$d->sayhello("fsdfs");
		print_r(get_class($d));
		print_r(get_class_methods('Unicom\Controller\Document'));

		var_dump(get_parent_class($d));
		var_dump(get_class_vars($d));
		$reclass = new \ReflectionClass('Unicom\Controller\Document');
		\Reflection::export($reclass);
	}

	private function say(Person $p) {
		var_dump($p);
	}

	private function say1() {

		$p = md5("qazxswedcv");
		var_dump($p);

	}


	public function verify(){
        $config =    array(
            'fontSize'    =>    8,    // 验证码字体大小
            'length'      =>    4,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
            'imageW'=>50,
            'imageH'=>22,
            'codeSet'=>"1234567890",
            'useCurve'=>true

        );
        $Verify = new \Think\Verify($config);

        $Verify->entry();

    }

}